package com.hilda.HTMLParserTesting;

import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.widget.TextView;

import com.hilda.HTMLParserTesting.htmlCleaner.HildaHtmlCleaner;

/**
 * TODO: Use -> twitpic.com/show/large/[id] to download a twitpic images
 * 
 * @author olidroide
 * 
 */
public class CrawDroidActivity extends Activity {
	private static String[] URL = {
			"http://www.google.com/",
			"http://www.theverge.com/2011/10/18/blackberry-bbx-announced-stub/",
			"http://hc.apache.org/httpcomponents-client-ga/",
			"http://www.enyojs.com", "http://code.google.com/p/hilda-twitter/",
			"http://www.elandroidelibre.com/", "http://t.co/aUYwZiSl",
			"http://goo.gl/AaJP9", "http://twitpic.com/8jr65t",
			"http://twitpic.com/show/large/8jr65t",
			"http://uax.es/moviles/web/","http://fb.me/VAp0dY24" };

	private NotifyHandler mNotifyHandler;
	private TextView mTvDownloadText;

	public static final int DOWNLOAD_OK = 0;
	public static final int DOWNLOAD_KO = -1;

	class NotifyHandler extends Handler {

		@Override
		public void handleMessage(Message msg) {
			switch (msg.what) {
			case DOWNLOAD_OK:
				String filePath = (String) msg.obj;
				mTvDownloadText.setTextColor(Color.GREEN);

				mTvDownloadText.setText("Download Complete! -->" + filePath);
				break;
			case DOWNLOAD_KO:
				mTvDownloadText.setTextColor(Color.RED);
				mTvDownloadText.setText("Download ERROR!");
				break;
			}

			super.handleMessage(msg);
		}

	}

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		mTvDownloadText = (TextView) findViewById(R.id.downloadText);
		mTvDownloadText.setText("Download Started!");
		mNotifyHandler = new NotifyHandler();

		// htmlCleaner http://htmlcleaner.sourceforge.net/
		// Good choice, easy, and fast
		HildaHtmlCleaner hildaHtmlCleaner = new HildaHtmlCleaner(this,
				mNotifyHandler);
		hildaHtmlCleaner.parse(URL[5]);

		// Test with my Own Crawler from
		// http://java.sun.com/developer/technicalArticles/ThirdParty/WebCrawler/WebCrawler.java
		// WebCrawler webCrawler = new WebCrawler(getApplicationContext());
		// webCrawler.init();
		// webCrawler.run();

		// Test with crawler4j from: http://code.google.com/p/crawler4j
		// Doesn't work
		// Crawler4j crawler4j = new Crawler4j(getApplicationContext());
		// WebURL webURL = new WebURL();
		// webURL.setURL("http://www.google.com");
		// crawler4j.shouldVisit(webURL);
		//
		// Controller c = new Controller(getApplicationContext());
		// try {
		// c.main();
		// } catch (Exception e) {
		// Log.v("crawDroid", e.getMessage());
		// }

		// Test with Jsoup: http://jsoup.org/
		// JsoupParser jsoupParser = new JsoupParser(this);

		// Test with Jtidy: http://jtidy.sourceforge.net/
		// Good choice, easy, and fast
		// HildaJtidy hildaJtidy = new HildaJtidy(this);
		// hildaJtidy.parse(URL[3]);

		// TagSoup http://ccil.org/~cowan/XML/tagsoup/
		// Low level complexity, and transform to XML
		// HildaTagSoup hildaTagSoup = new HildaTagSoup(this);
		// hildaTagSoup.parse(URL5);

		// saveWebArchive() method from webview use API LEVEL 11
		// HildaWebView hildaWebView = new HildaWebView(this);
		// hildaWebView.parse(URL[3]);
	}
}